package com.qidian.mes.pro.controller;

import com.qidian.mes.pojo.pro.ProProcess;
import com.qidian.mes.pojo.pro.ProRoute;
import com.qidian.mes.pro.service.ProRouteService;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 郭靖旖
 * @Company
 * @Time 2023/11/2 14:29
 * @Description
 **/
@RestController
@RequestMapping("/route")
@CrossOrigin
public class ProRouteController {
    @Autowired
    ProRouteService proRouteService;
    @GetMapping("/get")
    public MESResult selectallByPage(int page, int limit){
        return proRouteService.selectallByPage(page,limit);
    }
    @GetMapping("/list")
    public MESResult selectByPage(int page,int limit,ProRoute proRoute){
        return proRouteService.selectByPage(page,limit,proRoute);
    }
    @RequestMapping("/genRouteCode")
    public MESResult GenerateRouteCode(){
        return proRouteService.genRouteCode();
    }
    @PostMapping("/save")
    public MESResult save(@RequestBody ProRoute proRoute){
        if (proRoute.getEnableFlag()=='1'){
            proRoute.setEnableFlag('Y');
        }
        else if (proRoute.getEnableFlag()=='2'){
            proRoute.setEnableFlag('N');
        }
        return proRouteService.save(proRoute);
    }
    @DeleteMapping("/deletRoute")
    public MESResult deleteRoute(String routeCode){
        return proRouteService.deleteRoute(routeCode);
    }
    @PostMapping("/update")
    public MESResult updateProcess(@RequestBody ProRoute proRoute){
        if (proRoute.getEnableFlag()=='1'){
            proRoute.setEnableFlag('Y');
        }
        else if (proRoute.getEnableFlag()=='2'){
            proRoute.setEnableFlag('N');
        }
        return proRouteService.updateProRoute(proRoute);
    }
}
